package cn.nvr.file.conversion.enu;

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;


/**
 * 文件类型enu
 *
 * @author le.yang
 * @date 2021/06/17
 */
@Getter
@AllArgsConstructor
public enum FileTypeEnu {

    WORD(1, "word"),
    EXCEL(2, "excel"),
    PPT(3, "ppt"),
    PDF(4, "pdf"),
    TXT(5, "txt"),
    ;

    @JsonValue
    private final int code;

    private final String message;

    public static Optional<FileTypeEnu> valueOfByCodeOpt(int code) {
        return Arrays.stream(values()).filter(enu -> enu.getCode() == code).findFirst();
    }

    public static FileTypeEnu valueOfByCode(int code) {
        return valueOfByCodeOpt(code).orElseThrow(() -> new RuntimeException("请输入正确的文件类型"));
    }
}
